package cn.credit.loan.controller;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.credit.loan.entity.Creditresult;
import cn.credit.loan.service.creditresult.CreditresultService;
/**
 * 授信额度评分控制类
 * @author 
 *
 */
@Controller
public class CreditresultController {
	//日志输出
	private Logger logger = Logger.getLogger(CreditresultController.class);
	@Autowired
	private CreditresultService creditresultService;
	
	/**
	 *  授信额度评分
	 * @param creditresult
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/creditresultlist")
	@ResponseBody
	public Object creditresultlist(Creditresult creditresult,ModelMap model)
	{
		try {
			List<Creditresult> creditresultlist=creditresultService.getCreditresutList(creditresult);
			if(creditresultlist!=null)
			{
				model.addAttribute("creditresult", creditresult);
				return creditresultlist;
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
		
	}
	/**
	 * 授信额度添加
	 * @param creditresult
	 * @param model
	 * @return
	 */
	@RequestMapping("/creditresultadd")
	public String creditresultAdd(Creditresult creditresult,ModelMap model)
	{
		try {
			creditresult.setLoanId(5);
			creditresult.setManagerId(5);
			boolean creditresultadd=creditresultService.getCreditresultAdd(creditresult);
			if(creditresultadd)
			{
				model.addAttribute("creditresult", creditresult);
				return "CreditresultAdd";
			}
		} catch (Exception e) {
		
			e.printStackTrace();
		}
		return null;
		
	}
	
	/**
	 * 授信额度更新
	 * @param creditresult
	 * @param model
	 * @return
	 */
	@RequestMapping("/creditresultupdate")
	public String creditresultupdate(Creditresult creditresult,ModelMap model)
	{
		try {
			creditresult.setLoanId(6);
			creditresult.setManagerId(3);
			creditresult.setLevelId(6);
			boolean creditresultupdate=creditresultService.getCreditresultUpdate(creditresult);
			if(creditresultupdate)
			{
				model.addAttribute("creditresult", creditresult);
				return "CreditresultUpdate";
			}
		} catch (Exception e) {
		
			e.printStackTrace();
		}
		return null;
	}
	/**
	 * 授信额度删除
	 * @param creditId
	 * @param model
	 * @return
	 */
	@RequestMapping("/creditresultdelete")
	public String  creditresultdelete(int creditId,ModelMap model)
	{
		try {
			boolean creditIds=creditresultService.getCreditresultDelete(creditId);
			if(creditIds)
			{
				model.addAttribute("creditId",creditId);
				return "CreditresultDelete";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	

}
